package com.software.controller;


import com.software.base.ResultInfo;
import com.software.bean.ProductImageBean;
import com.software.dto.ProductDetailImageDto;
import com.software.service.ProductImageService;
import com.software.utils.AssertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wyj
 * @since 2024-03-24
 */
@Controller
@RequestMapping("/productImage")
public class ProductImageController {

    @Autowired
    private ProductImageService productImageService;

    @PostMapping("/front/postProductDetailImage")
    @ResponseBody
    public ResultInfo postProductDetailImage(ProductDetailImageDto detailImageDto) {
        Integer result = productImageService.postDetailImage(detailImageDto);
        AssertUtil.isTrue(result != 1, "插入失败");
        return ResultInfo.success();
    }

    @GetMapping("/api/getProductDetailImageList/{productId}")
    @ResponseBody
    public ResultInfo getProductDetailImageList(@PathVariable Integer productId) {
        List<ProductImageBean> list = productImageService.getProductDetailImageList(productId);
        return ResultInfo.success(list.size(), list);
    }
}
